home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 2004 April / SGI IRIX 6.5 Applications 2004 April.iso / dist / appletalk.idb / usr / etc / appletalk / atinit.z / atinit
Text File  |  2002-03-07  |  4KB  |  183 lines

  1. #! /bin/csh -f
  2. #
  3. #
  4. #  Copyright (c) 1985, 1992
  5. #  by Xinet Inc.  All Rights Reserved.
  6. #    @(#)atinit.sh    10.1    99/10/14    Xinet
  7. #
  8. #script to start, stop, or restart appletalk servers
  9.  
  10. set path=( /usr/etc/appletalk /bin /usr/{bin,etc,bsd,ucb,sbin} /etc )
  11. set p=$0
  12. set p=$p[1]:t
  13.  
  14. if ( $#argv < 1 ) then
  15.     echo "Usage:  $p [start | halt | restart]"
  16.     exit 1
  17. endif
  18. if (-x /bin/id) then
  19.     if (`/bin/id | grep -c uid=0` > 0) then
  20.         set me=root
  21.     else
  22.         set me=notroot
  23.     endif
  24. else
  25.     set me=`whoami`
  26. endif
  27. if ("$me" != root) then
  28.     echo "You must have root privileges to run this script"
  29.     exit 1
  30. endif
  31.  
  32.  
  33. set CONF_PATH=/usr/etc/appletalk
  34. set SERVICES=$CONF_PATH/services
  35. set ADM_PATH=/usr/adm/appletalk
  36. set NBP_PID=$ADM_PATH/nbp_pid
  37. set AT_PIDS=$ADM_PATH/nbpreg_pids
  38. set TMPA=/tmp/atinitA$$
  39.  
  40. foreach arg ($*)
  41.     #evaluate any arguments that assign a value:
  42.     echo $arg | grep -s '='
  43.     if ($status == 0) then
  44.         eval set $arg
  45.     endif
  46. end
  47.  
  48. set SERVERS=()
  49. if (-f $SERVICES) then
  50.     set SERVERS=(`grep -v '#' $SERVICES | awk '{print $1}'`)
  51. endif
  52.  
  53. #if no services, then done:
  54. if ($#SERVERS == 0) then
  55.     exit 0
  56. endif
  57.  
  58. switch ($1)
  59. case start:
  60. case halt:
  61. case restart:
  62.     set action=$1
  63.     breaksw
  64. case START:
  65.     set action=start
  66.     breaksw
  67. case HALT:
  68.     set action=halt
  69.     breaksw
  70. case RESTART:
  71.     set action=restart
  72.     breaksw
  73. default:
  74.     echo "Usage:  $p [start | halt | restart]"
  75.     exit 1
  76.     breaksw
  77. endsw
  78.  
  79. #kill servers if halt or restart:
  80. if ($action == halt|| $action == restart) then
  81.     if (-f $NBP_PID || -f $AT_PIDS) then
  82.         if (-f $NBP_PID) then
  83.             cat $NBP_PID
  84.             echo "nbpd"
  85.             set nbppid=`awk '{print $1}' $NBP_PID`
  86.         else
  87.             set nbppid=0
  88.         endif
  89.         cat $AT_PIDS
  90.  
  91.         set atpids=`awk '{print $1}' $AT_PIDS`
  92.  
  93.         if ($#atpids > 0) then
  94.             echo Killing $atpids
  95.             foreach atp ($atpids)
  96.                 (kill $atp >& /dev/null)
  97.                 #NOTE:    kill executed in sub-shell to prevent us
  98.                 #    from exiting on error (kill is a csh builtin)
  99.             end
  100.             sleep 1
  101.             foreach atp ($atpids)
  102.                 (kill $atp >& /dev/null)
  103.                 #NOTE:    kill executed in sub-shell to prevent us
  104.                 #    from exiting on error (kill is a csh builtin)
  105.             end
  106.             sleep 2
  107.             foreach atp ($atpids)
  108.                 #just to make sure:
  109.                 (kill -9 $atp >& /dev/null)
  110.             end
  111.         endif
  112.  
  113.         if ($#nbppid > 0 && $nbppid > 0) then
  114.             #kill nbpd last, so other servers can de-register:
  115.             echo Killing nbpd server $nbppid
  116.             (kill $nbppid >& /dev/null)
  117.         endif
  118.     else
  119.         echo "AppleTalk services already halted..."
  120.     endif
  121.     rm -f $AT_PIDS
  122. endif
  123.  
  124. if ($action == halt) then
  125.     #done, exit normally
  126.     if (-x ${CONF_PATH}/atconfig) then
  127.         ${CONF_PATH}/atconfig -clear
  128.     endif
  129.     exit 0
  130. endif
  131.  
  132. #if we are restarting, we clear the interface and sleep to let routes re-build
  133. if ($action == restart) then
  134.     if (-x ${CONF_PATH}/atconfig) then
  135.         echo "Clearing AppleTalk configuration (takes 10 seconds)"
  136.         ${CONF_PATH}/atconfig -clear
  137.         sleep 10
  138.     endif
  139.     awk -F\     '$2 != "R" {print}' $SERVICES > $TMPA
  140. else
  141.     if (-e $AT_PIDS) then
  142.         echo "AppleTalk Services already running"
  143.         exit 1
  144.     endif
  145.     awk -F\     '{print $1}' $SERVICES > $TMPA
  146.     #clear the log file on start but not restart
  147.     if (-e /usr/adm/appletalk/at_log) then
  148.         rm -f /usr/adm/appletalk/at_log.old
  149.         mv /usr/adm/appletalk/at_log /usr/adm/appletalk/at_log.old
  150.         touch /usr/adm/appletalk/at_log
  151.         chmod 666 /usr/adm/appletalk/at_log
  152.     else if  (-e /var/adm/appletalk/at_log) then
  153.         rm -f /var/adm/appletalk/at_log.old
  154.         mv /var/adm/appletalk/at_log /var/adm/appletalk/at_log.old
  155.         touch /var/adm/appletalk/at_log
  156.         chmod 666 /usr/adm/appletalk/at_log
  157.     endif
  158.     if (-e /var/adm/appletalk/fpo_log) then
  159.         rm -f /var/adm/appletalk/fpo_log.old
  160.         mv /var/adm/appletalk/fpo_log /var/adm/appletalk/fpo_log.old
  161.         touch /var/adm/appletalk/fpo_log
  162.         chmod 666 /usr/adm/appletalk/fpo_log
  163.     endif
  164. endif
  165.  
  166.  
  167.  
  168. set SERVICES=$TMPA
  169. set SERVERS=(`grep -v '#' $SERVICES | awk '{print $1}'`)
  170.     
  171. echo -n "AppleTalk Services: "
  172. foreach srvr ($SERVERS)
  173.     if (-x $srvr) then
  174.         #list server:
  175.         echo -n " $srvr:t"
  176.     endif
  177. end
  178. echo .
  179. csh -fe $SERVICES
  180. set x=$status
  181. rm -f $TMPA
  182. exit $x
  183.